package BusinessLogic;

import Presentation.frmLogin;
import java.io.*;

public class Connection{
    static frmLogin login;
    static ClientServices cs=null;
    static int port=12345;
    Thread th;
    
    public boolean connect(String ip){
        try{
            if(cs==null){
                cs = new ClientServices(ip, port);
                return true;
            }
            else return true;
        }
        catch(Exception e){
            return false;
        }
    }
    
    public static boolean isConnected(){
        if(cs.Connected){
            return true;
        }
        else return false;
    }
    
    public static void logout() throws IOException{
        cs.stop();
        cs=null;
    }
    
    public static void reConnect(){
        cs=null;
    }
    
    public static void exitProgram() throws IOException{
        if(cs!=null) if(cs.Connected) cs.stop();
        System.exit(0);
    }

    public static boolean sendData(String str){
        if(cs.sendData(str)){ return true;}
        else return false;
    }

}